/**   
 * @文件名称: SysRole.java
 * @类路径: cn.ccew.sys.model
 * @描述: TODO
 * @公司：春城1网
 * @作者：李兴建
 * @时间：2013-10-1 下午12:31:19
 * @版本：V1.0   
 */

package cn.ccew.sys.model;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import cn.ccew.common.base.model.BaseEntity;

/**
 * @类功能说明：角色
 * @类修改者：
 * @修改日期：
 * @修改说明：
 * @公司：春城1网
 * @作者：李兴建
 * @创建时间：2013-10-1 下午12:31:19
 * @版本：V1.0
 */

@Entity
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@Table(name = "sys_role")
public class SysRole extends BaseEntity {
	/**
	 * 角色名称
	 */
	private String roleName;
	/**
	 * 角色图标
	 */
	private String roleImage;
	/**
	 * 角色描述
	 */
	private String roleDescription;
	/**
	 * 角色等级[0:普通管理员 1：超级管理员]
	 */
	private int roleLayer;
	@Transient
	private String roleLayerString;

	/**
	 * 所有操作
	 */
	// 级联保存、更新、删除、刷新;延迟加载
	@ManyToMany(cascade = CascadeType.MERGE, fetch = FetchType.LAZY)
	// 在book表增加一个外键列来实现一对多的单向关联
	@JoinTable(name = "sys_role_resources", joinColumns = { @JoinColumn(name = "role_id") }, inverseJoinColumns = { @JoinColumn(name = "resources_id") })
	private Set<SysResources> resources = new HashSet<SysResources>();

	public String getRoleName() {
		return roleName;
	}

	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}

	public String getRoleImage() {
		return roleImage;
	}

	public void setRoleImage(String roleImage) {
		this.roleImage = roleImage;
	}

	public String getRoleDescription() {
		return roleDescription;
	}

	public void setRoleDescription(String roleDescription) {
		this.roleDescription = roleDescription;
	}

	public int getRoleLayer() {
		return roleLayer;
	}

	public void setRoleLayer(int roleLayer) {
		this.roleLayer = roleLayer;
	}

	public Set<SysResources> getResources() {
		return resources;
	}

	public void setResources(Set<SysResources> resources) {
		this.resources = resources;
	}

	public String getRoleLayerString() {
		// 角色等级[0:普通管理员 1：超级管理员]
		switch (roleLayer) {
		case 0:
			roleLayerString = "普通管理员";
			break;
		case 1:
			roleLayerString = "超级管理员";
			break;

		default:
			break;
		}
		return roleLayerString;
	}

	public void setRoleLayerString(String roleLayerString) {
		this.roleLayerString = roleLayerString;
	}

}
